<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CrossRefEdit extends Page
{
       public $edPartDesc = null;
       public $JTDivManufacturer = null;
       public $JTGroupBox1 = null;
       public $btnAddManufacturer = null;
       public $btnDelManufacturer = null;
       public $edManufacturer = null;
       public $listManufacturer = null;
       public $cmbInvType = null;
       public $Label7 = null;
       public $cmbParts = null;
       public $Label3 = null;
       public $btnShowManufacturer = null;
       public $memoCommnents = null;
       public $lblFullDescription = null;
       public $cmbVend = null;
       public $Label2 = null;
       public $cmbMnfr = null;
       public $lblDescription = null;
       public $JTSiteTheme1 = null;
       public $compid = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $Button2 = null;
       public $Button1 = null;
       public $imgBack = null;
       public $hiddenStock = null;
       public $hiddenParts = null;
       public $Image1 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       function cmbInvTypeJSChange($sender, $params)
       {
       echo $this->cmbInvType->ajaxCall('cmbInvChange');
        ?>
        return(false);
        <?php

       }


       function btnDelManufacturerJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var mnfrIndex = document.getElementById('listManufacturer').selectedIndex;
       var mnfrValue = document.getElementById('listManufacturer')[mnfrIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxMnfr3(mnfrValue,compider3);
       <?php

       }

       function btnAddManufacturerJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addmnfr = document.getElementById('edManufacturer').value;
       var compider = document.getElementById('compid').value;
       AjaxMnfr2(addmnfr,compider);
       document.CrossRefEdit.edManufacturer.value = "";
       <?php

       }

       function btnShowManufacturerJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivManufacturer').Show();
       document.CrossRefEdit.edManufacturer.value = "";
       <?php

       }


       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnCancelClick($sender, $params)
       {
        redirect('veh_parts_crossref_list.php?stock_id='.$this->hiddenStock->getValue());


       }

       function btnSubmitClick($sender, $params)
       {
       $query_update = "UPDATE veh_parts_crossref SET
       manufacturer='".$this->cmbMnfr->getItemIndex()."',
       vendor='".$this->cmbVend->getItemindex()."',
       inv_type='".$this->cmbInvType->getItemindex()."',
       part_description='".$this->cmbParts->getItemindex()."',
       comments='".$this->memoCommnents->Text."'

       WHERE auto='".$this->hiddenParts->getValue()."'";
       mysql_query($query_update) or die(mysql_error());


       redirect('veh_parts_crossref_list.php?stock_id='.$this->hiddenStock->getValue());


       }




       function cmbInvChange($sender, $params)
       {

       $inventory_id = $this->cmbInvType->getItemIndex();
       $this->cmbParts->Clear();
       $this->cmbParts->AddItem('--Select--', null, null);
       $result_inv = mysql_query("select * from invstocks_tbl where company_id = '".$_SESSION['company_id']."' and type='".$inventory_id."'");

       while($row_inv = mysql_fetch_array($result_inv))
       {
            $this->cmbParts->AddItem($row_inv['stock_num'].'-'.$row_inv['description'], null, $row_inv['stock_id']);
       }

       }







       function CrossRefEditCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $part = $_GET['part'];
       $stock = $_GET['stock_id'];
       $this->hiddenParts->setValue($part);
       $this->hiddenStock->setValue($stock);

       if($_SESSION['access_part']==1)
       {
       $this->Button1->Visible=false;
       $this->Button2->Visible=false;
       $this->btnSubmit->Visible=false;
       $this->btnCancel->Visible=false;
       }

       if($_SESSION['access_part']==2)
       {
       $this->Button1->Visible=true;
       $this->Button2->Visible=true;
       $this->btnSubmit->Visible=true;
       $this->btnCancel->Visible=true;
       }


       $query1 = "select * from veh_parts_crossref where stock_id='".$this->hiddenStock->getValue()."' and auto='".$this->hiddenParts->getValue()."'";
       $result = mysql_query($query1)or die(mysql_error());
       $row_crossref = mysql_fetch_array($result);

       //$this->edPartNum->Text=$row_crossref['part_num'];
       //$this->edPartName->Text=$row_crossref['part_name'];
       $this->memoCommnents->Text=$row_crossref['comments'];


       $selected_invtype = $row_crossref['inv_type'];
       $result_sel_inv = mysql_query("SELECT * FROM invstocks_tbl WHERE type='".$selected_invtype."'") or die("GET INV".mysql_error());
       $row_sel_inv = mysql_fetch_array($result_sel_inv);

       $selected_desc = $row_crossref['part_description'];
       $result_sel_desc = mysql_query("SELECT * FROM invstocks_tbl WHERE stock_id='".$selected_desc."'") or die("GET DESC".mysql_error());
       $row_sel_desc = mysql_fetch_array($result_sel_desc);


        $this->cmbInvType->Clear();
        $this->cmbInvType->AddItem('--Select--', null, null);
        $result_type = mysql_query("select * from lookup_inventory_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbInvType->AddItem($row_type['value'], null, $row_type['value']);
        }
        $this->cmbInvType->ItemIndex = $row_sel_inv['type'];

       $this->cmbParts->Clear();
       $selected_part = $row_sel_desc['stock_num'].'-'.$row_sel_desc['description'];
       $this->cmbParts->AddItem($selected_part, null, $selected_part);
       $result_part = mysql_query("select * from invstocks_tbl where company_id = '".$_SESSION['company_id']."' and type='".$selected_invtype."'");
       while($row_part = mysql_fetch_array($result_part))
       {
           $part = $row_part['stock_num'].'-'.$row_part['description'];
           if($selected_part!=$part)
           $this->cmbParts->AddItem($part, null, $part);
       }



        $this->cmbMnfr->Clear();
        $this->cmbMnfr->AddItem('--Select--', null, null);
        $this->cmbMnfr->ItemIndex=$row_crossref['manufacturer'];
        $result_mnfr = mysql_query("select * from lookup_inventory_tbl where company_id='".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_mnfr = mysql_fetch_array($result_mnfr))
        {
            $this->cmbMnfr->AddItem($row_mnfr['value'], null, $row_mnfr['value']);
        }

        //list manufacturer
        $this->listManufacturer->Clear();
        $result_m = mysql_query("select * from lookup_inventory_tbl where company_id='".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_m = mysql_fetch_array($result_m))
        {
            $this->listManufacturer->AddItem($row_m['value'], null, $row_m['value']);
        }

       $this->cmbVend->Clear();
       $this->cmbVend->AddItem('--Select--', null, null);
       $this->cmbVend->ItemIndex=$row_crossref['vendor'];
        $result_vend = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_vend = mysql_fetch_array($result_vend))
        {
            $this->cmbVend->AddItem($row_vend['vendor_name'], null, $row_vend['vendor_name']);
        }

        $this->imgBack->setLink('veh_parts_crossref_list.php?stock_id='.$this->hiddenStock->getValue());
       }

}

global $application;

global $CrossRefEdit;

//Creates the form
$CrossRefEdit=new CrossRefEdit($application);

//Read from resource file
$CrossRefEdit->loadResource(__FILE__);

//Shows the form
$CrossRefEdit->show();

?>